package dao

import (
	"go/models"
)

func AddHonor(honor models.Honor) error {
	// err := db.Table("student_message").Select("sno", "sname", "ssex", "sage", "sdept", "sedu_sys", "sregion", "spolitics", "snation").Create(&student).Error
	err := db.Table("honor").Create(&honor).Error
	return err
}

func DelHonor(sno int) error {
	err := db.Table("honor").Where("sno = ?", sno).Update("is_del", true).Error
	return err
}

func UpdateHonor(honor models.Honor) error {
	sno := honor.Sno
	err := db.Table("honor").Where("sno = ?", sno).Updates(&honor).Error
	return err
}

func GetHonor(honorParam map[string]interface{}) ([]models.Honor, int64, error) {
	var honorData []models.Honor
	page := honorParam["page"].(int)
	pageSize := honorParam["limit"].(int)
	searchName := honorParam["searchName"].(string)
	var total int64
	err := db.Table("honor").Where("sno like ? AND is_del = false", searchName+"%").Order("sno ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&honorData).Error
	return honorData, total, err
}
